package min_heap

import (
	"errors"
	"fmt"
)

var (
	ErrMaxHeapIsEmpty = errors.New("MaxHeap is Empty")
)

type MinHeap struct {
	data []int
}

func (h *MinHeap) Size() int { return len(h.data) }

func (h *MinHeap) IsEmpty() bool { return len(h.data) == 0 }

func parent(index int) int {
	if index <= 0 {
		panic("index-0 doesn't has parent node")
	}
	return (index - 1) / 2
}

func leftChild(index int) int { return (index * 2) + 1 }

func rightChild(index int) int { return (index * 2) + 2 }

// Add 添加
func (h *MinHeap) Add(elem int) {

}

// 上浮
func (h *MinHeap) siftUp(k int) {}

// FindMin 查看最小值
func (h *MinHeap) FindMin() (int, error) {
	return -1, nil
}

// ExtractMin 提取最小值
func (h *MinHeap) ExtractMin() (int, error) {
	return -1, nil
}

// 下沉
func (h *MinHeap) siftDown(k int) (int, error) {
	return -1, nil
}

// 字符串表示
func (h *MinHeap) String() string {
	return fmt.Sprintf("MinHeap: %v\n", h.data)
}

// NewMinHeap 创建最小堆
func NewMinHeap(elems ...int) *MinHeap {
	heap := &MinHeap{data: make([]int, len(elems))}
	for _, elem := range elems {
		heap.Add(elem)
	}
	return heap
}
